package com.yc.game.controller;

import com.github.pagehelper.PageInfo;
import com.yc.game.pojo.Category;
import com.yc.game.pojo.Food;
import com.yc.game.pojo.Recipes;
import com.yc.game.pojo.TrainingContent;
import com.yc.game.service.CategoryService;
import com.yc.game.service.FoodService;
import com.yc.game.service.RecipesService;
import com.yc.game.service.TrainingContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class PageController {
    @Autowired
    private RecipesService recipesService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private FoodService foodService;
    @Autowired
    private TrainingContentService contentService;

    @RequestMapping("page/index")
    public String pageIndex(ModelMap modelMap) {
        List<Recipes> recipes = recipesService.getRandom();
        modelMap.addAttribute("recipes", recipes);
        List<Category> categories = categoryService.getAll();
        modelMap.addAttribute("categories", categories);
        List<Food> foods = foodService.getByHot();
        modelMap.addAttribute("foods", foods);
        return "index";
    }

    @RequestMapping("page/notFound")
    public String pageNotFound() {
        return "404";
    }

    /**
     * 跳转到代练页面
     */
    @RequestMapping("page/training")
    public String trainingPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                               ModelMap modelMap) {
        // 查询所有的代练信息
        PageInfo<TrainingContent> contentPageInfo = contentService.getAll(pageNum, pageSize);
        modelMap.addAttribute("contentPageInfo", contentPageInfo);
        List<Category> categories = categoryService.getAll();
        modelMap.addAttribute("categories", categories);
        return "training";
    }



}
